package com.microsoft.tag.server.user.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 软件著作权:王艳明
 * 系统名称:SpringBoot后台管理系统
 *
 * @author WangYanming
 * @ClassName 类:UserController.java
 * @Description 功能描述:user controller
 * @Version 1.0
 * @date 2025-10-14 下午 04:59
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    // SentinelResource注解保护资源
    @SentinelResource(value = "getUser", blockHandler = "getUserBlockHandler")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String getUser(@PathVariable(value = "id") Long id) {
        // new UserResponse(10000L, "WangYanMing", "王艳明");
        return "{\"id\": " + id + "}";
    }

    // 限流/熔断后的处理方法
    public String getUserBlockHandler(Long id, BlockException e) {
        System.out.println("id:" + id);
        System.out.println("异常:" + e);
        return "获取用户信息失败,已触发限流/熔断包含";
    }
}
